package com.hongning.railway.ui.main.fragments.threesessionsandonelesson;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.databinding.ActivityThreesessionsandonelessonBinding;
import com.hongning.railway.databinding.FragmentHomeBinding;
import com.hongning.railway.entity.reqbean.MettingMessageBean;
import com.hongning.railway.ui.main.fragments.college.LearnCompleteFragment;
import com.hongning.railway.ui.main.fragments.college.LearnCompleteFragmentViewModel;
import com.hongning.railway.ui.main.fragments.home.HomeViewModel;
import com.hongning.railway.util.Apputils;

import me.goldze.mvvmhabit.base.BaseFragment;

public class ThreesessionSanDoneLessonFragment extends BaseFragment<ActivityThreesessionsandonelessonBinding, ThreesessionSanDoneLessonViewModel> {
    public static ThreesessionSanDoneLessonFragment newInstance() {

        Bundle args = new Bundle();

        ThreesessionSanDoneLessonFragment fragment = new ThreesessionSanDoneLessonFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.activity_threesessionsandonelesson;
    }

    @Override
    public int initVariableId() {
        return BR.threesessionSanDoneLessonViewModel;
    }
    @Override
    public ThreesessionSanDoneLessonViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(ThreesessionSanDoneLessonViewModel.class);
    }
    @Override
    public void initData() {
        super.initData();
        Apputils.setDefaultHeaderView(binding.trRefhreh);
        binding.rvContent.setItemAnimator(null);
        binding.layoutStatus.ivStatu.setImageResource(R.mipmap.icon_nocontent);
        binding.layoutStatus.tvStatu.setText("暂无内容");
        viewModel.initDatas(new MettingMessageBean());
    }

    @Override
    public void initViewObservable() {
        viewModel.uc.finishRefresh.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.finishRefreshing();
                binding.trRefhreh.setEnableLoadmore(true);
//                binding.trRefhreh.setHeaderView();

            }
        });

        viewModel.uc.finishLoadMore.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.finishLoadmore();
            }
        });

        viewModel.uc.finishLoadMoreEnd.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                binding.trRefhreh.setEnableLoadmore(false);
            }
        });

    }
}
